#!/usr/bin/env python
# -*- coding: utf-8 -*-
#code:utf-8
#
# Copyright(C) 2011 SupDo.com
# Licensed under the GUN License, Version 3.0 (the "License");
# 
# File:        tmplate.py
# Author:      KuKei
# Create Date: 2012-05-24
# Description: 公用函数库
# Modify Date: 2012-05-24

from django.template import loader, Context
from sd.cms.lib.decorator import cacheTheme
from django.http import HttpResponse

class Template():
    tpl = None
    #@cacheTheme()
    def getTpl(self, theme, tplUrl):
        self.tpl = None
        try:
            #aa = loader.render_to_string(theme+tplUrl)
            self.tpl = loader.find_template(theme+tplUrl)
        except Exception,ex:
            self.tpl = loader.find_template('default'+tplUrl)
        return self.tpl
            
    def render(self, context, tpl=None):
        if not tpl:
            tpl = self.tpl
        return HttpResponse(tpl.render(Context(context)))